package com.dayu.web.controller.basic;

import java.util.List;

import com.dayu.common.annotation.Log;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dayu.common.core.controller.BaseController;
import com.dayu.common.core.domain.AjaxResult;
import com.dayu.common.enums.BusinessType;
import com.dayu.basic.domain.BasicClerk;
import com.dayu.basic.service.IBasicClerkService;
import com.dayu.common.utils.poi.ExcelUtil;
import com.dayu.common.core.page.TableDataInfo;

/**
 * 营业员管理Controller
 * 
 * @author HK
 * @date 2021-04-15
 */
@RestController
@RequestMapping("/basic/clerk")
public class BasicClerkController extends BaseController
{
    @Autowired
    private IBasicClerkService basicClerkService;

    /**
     * 查询营业员管理列表
     */
    @PreAuthorize("@ss.hasPermi('basic:clerk:list')")
    @GetMapping("/list")
    public TableDataInfo list(BasicClerk basicClerk)
    {
        startPage();
        List<BasicClerk> list = basicClerkService.selectBasicClerkList(basicClerk);
        return getDataTable(list);
    }

    /**
     * 导出营业员管理列表
     */
    @PreAuthorize("@ss.hasPermi('basic:clerk:export')")
    @Log(title = "营业员管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BasicClerk basicClerk)
    {
        List<BasicClerk> list = basicClerkService.selectBasicClerkList(basicClerk);
        ExcelUtil<BasicClerk> util = new ExcelUtil<BasicClerk>(BasicClerk.class);
        return util.exportExcel(list, "clerk");
    }

    /**
     * 获取营业员管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:clerk:query')")
    @GetMapping(value = "/{clerkId}")
    public AjaxResult getInfo(@PathVariable("clerkId") Long clerkId)
    {
        return AjaxResult.success(basicClerkService.selectBasicClerkById(clerkId));
    }

    /**
     * 新增营业员管理
     */
    @PreAuthorize("@ss.hasPermi('basic:clerk:add')")
    @Log(title = "营业员管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasicClerk basicClerk)
    {
        return toAjax(basicClerkService.insertBasicClerk(basicClerk));
    }

    /**
     * 修改营业员管理
     */
    @PreAuthorize("@ss.hasPermi('basic:clerk:edit')")
    @Log(title = "营业员管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasicClerk basicClerk)
    {
        return toAjax(basicClerkService.updateBasicClerk(basicClerk));
    }

    /**
     * 删除营业员管理
     */
    @PreAuthorize("@ss.hasPermi('basic:clerk:remove')")
    @Log(title = "营业员管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{clerkIds}")
    public AjaxResult remove(@PathVariable Long[] clerkIds)
    {
        return toAjax(basicClerkService.deleteBasicClerkByIds(clerkIds));
    }
}
